<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
//for stock
ini_set("display_errors",1);
error_reporting(E_ALL);


function group_assoc($array, $key) {
    $return = array();
    foreach($array as $v) {
        $return[$v[$key]][] = $v;
    }
    return $return;
}

function toArray($obj)
{
    if (is_object($obj)) $obj = (array)$obj;
    if (is_array($obj)) {
        $new = array();
        foreach ($obj as $key => $val) {
            $new[$key] = toArray($val);
        }
    } else {
        $new = $obj;
    }
    return $new;
}


try {
    $url = "http://api.dddadmin.com/StockService.svc?wsdl";
    $client = new SoapClient($url);
    echo '<pre>';
	
	//var_dump($client->__getFunctions());
	
	$shopid = "855001";
	$myKey	= "vkal29xcjs81lslc8qlxpgg63anxaqk2ixkskxm19m";
	
	$params['clientid'] = "855001";
	$params['psk'] = "vkal29xcjs81lslc8qlxpgg63anxaqk2ixkskxm19m";
	
	
	$articles = $client->GetWebshopArticles($params);
	//var_dump($articles);
	$strInfo = ($articles->GetWebshopArticlesResult);
	$arrInfo = toArray(json_decode($strInfo));
	
	$group_products = group_assoc($arrInfo, 'Supplier');
	
	echo "<table border=\"1\">";
	echo "<th>Index</th>";
	echo "<th>Supplier ID</th>";
	
	echo "<th>SupplierName</th>";
	
	//var_dump($group_products);
	$index = 1;
	foreach($group_products as $key=>$value){
		
		
		$SupplierName 	= $value[0]['SupplierName'];
	
		$Supplier 		= $key;
		
		echo "<tr>";
		echo "<td>".$index."</td>";
		echo "<td>".$Supplier."</td>";
		echo "<td>".$SupplierName."</td>";
		
		
		echo "</tr>";
		
		$index++;
		
		
	}
	echo "</table>";
	
	
	echo '</pre>';
}
catch (SoapFault $exception) {
    echo $exception->getMessage();
}

?>
</body>
</html>